import matplotlib.pyplot as plt
import numpy as np

# fig, ax = plt.subplots(2,1) # 生成figure及包含于其中的2行1列共2个axes子图
# ax[0].plot([1,2,3,4],[1,4,2,3]) # 在子图1中绘制数据，两个列表分别表示数据的横纵坐标，即四个点的坐标分别为(1,1),(2,4),(3,2),(4,3)
# plt.show() # 展示图形

# fig.savefig('a.jpg')

# fig, ax = plt.subplots(2,1) # 生成figure及包含于其中的2行1列共2个axes子图
# # 在子图2上绘制数据，参数列表表示数据的纵坐标，横坐标默认从0开始的整数值
# # 即[0,1,2,3],因此四个点的坐标分别为(0,0),(1,1),(2,4),(3,9)
# ax[1].plot([0,1,4,9]) 
# plt.show()

# X = np.linspace(-np.pi, np.pi, 256, endpoint=True) #从-π到π均匀取 256 个点
# C,S = np.cos(X), np.sin(X) # 分别得到这些点的余弦值和正弦值生成的一维数组
# plt.plot(X,C) # 横坐标为X, 纵坐标为C，绘制曲线
# plt.plot(X,S) # 横坐标为X, 纵坐标为S，绘制曲线
# plt.show()

# fig, ax = plt.subplots(figsize=(5,2.7))
# y1,y2 = np.random.randint(20,size=(2,10))
# print(y1)
# print(y2)
# x = np.arange(len(y1))
# print(x)
# ax.plot(x,y1,color='blue',linewidth=3,linestyle='--')
# line, = ax.plot(x,y2,color='orange',linewidth=2,marker='o')
# line.set_linestyle(':') # 设置连线形状为点线
# plt.show()

# fig, ax = plt.subplots()
# x = np.linspace(-np.pi,np.pi,256) #从-π到π均匀取 256 个点
# ax.plot(x,np.sin(x),'-g',label='sin(x)') # '-g'表示线条样式为'-',颜色为'g'
# ax.plot(x,np.cos(x),':b',label='cos(x)') # ':b'表示线条样式为':',颜色为'b'
# ax.legend(fancybox=True)
# plt.show()

# fig, ax = plt.subplots()
# rng = np.random.RandomState(0) # 生成伪随机数生成器，随机数种子为0
# for marker in ['o','.',',','x','+','v','^','<','>','s','d']:
#       ax.plot(rng.rand(5),rng.rand(5),marker,label="marker='{}'".format(marker))

# plt.show()

# fig, ax = plt.subplots()
# rng = np.random.RandomState(0)
# x = rng.randn(100)
# y = rng.randn(100)
# colors = rng.rand(100)
# sizes = 1000 * rng.rand(100)
# axs = ax.scatter(x,y,c=colors,s=sizes,alpha=0.3)
# fig.colorbar(axs,ax=ax) # 设置右侧的颜色条

# plt.show()

# x = np.linspace(0,10,11) # 11个超参数值
# y = np.random.rand(10,11) # 模拟10次实验不同超参数值下的准确率
# mean = y.mean(axis=0) # 按列求平均
# std = y.std(axis=0) # 按列求方差
# fig, ax = plt.subplots()
# ax.errorbar(x,mean,yerr=std,fmt='.k',ecolor='r',elinewidth=2,capsize=4)
# plt.show()

# fig, ax = plt.subplots(2,2) # 2行2列四个子图
# x = np.linspace(0,5,50)
# y = np.linspace(0,3,30)
# X, Y = np.meshgrid(x,y)

# Z = np.sin(X) ** 10 + np.cos(10 + Y * X) * np.cos(X)
# h = ax[0][0].hist(Z) #左上子图绘制直方图
# axs01 = ax[0,1].pcolormesh(X,Y,Z,vmin=-1,vmax=1,cmap='RdBu_r') #右上子图绘制颜色图
# fig.colorbar(axs01,ax=ax[0,1]) # 子图帮绘制色条
# axs10 = ax[1][0].contourf(X,Y,Z,20) #左下子图绘制带有填充色的等高线图
# fig.colorbar(axs10,ax=ax[1][0]) # 子图帮绘制色条
# ax[1][1].contour(X,Y,Z,colors='k') #右下子图绘制等高线图

# plt.show()


# zline = np.linspace(0, 15, 1000)
# xline = np.sin(zline)
# yline = np.cos(zline)
# zdata = 15 * np.random.random(100)
# xdata = np.sin(zdata) + 0.1 * np.random.randn(100)
# ydata = np.cos(zdata) + 0.1 * np.random.randn(100)
# fig = plt.figure()
# ax = plt.axes(projection='3d')
# ax.plot3D(xline, yline, zline, 'gray')
# ax = plt.axes(projection='3d',xlabel='x',ylabel='y',zlabel='z')
# ax.plot3D(xline,yline,zline,'gray')
# ax.scatter3D(xdata, ydata, zdata, c=zdata, cmap='Greens');
# plt.show()

x = np.linspace(-6,6,30)
y = np.linspace(-6,6,30)
X,Y = np.meshgrid(x,y)
Z = np.sin(np.sqrt(X**2+Y**2))
fig = plt.figure()

ax = fig.add_subplot(221) # 221 表示当作2行2列，生成第一个二维子图，即左上子图
ax.contourf(X,Y,Z,50) # 绘制二维等高线
ax = fig.add_subplot(222,projection='3d') # 生成第2个三维子图，即右上子图
ax.contour3D(X,Y,Z,50) # 绘制三维等高线
ax = fig.add_subplot(223,projection='3d') # 生成第3个三维子图，即左下子图
ax.plot_wireframe(X,Y,Z,color='black') # 绘制网格图
ax = fig.add_subplot(224,projection='3d') # 生成第4个三维子图，即右下子图
ax.plot_surface(X,Y,Z) # 绘制曲面图
plt.show()